﻿using System;
using System.ComponentModel;

namespace LFSRecord2.Model
{
    public class AudioLayerPropertyBase : INotifyPropertyChanged, IDisposable
    {
        public bool Initializing { get; set; }
        public AudioLayer ParentLayer { get; protected set; }
        public int PropertyIndex { get; protected set; }
        public string PropertyName { get; protected set; }
        public LayerPropertyValueTypes PropertyValueType { get; protected set; }
        public LayerPropertyValueMeaning PropertyValueMeaning { get; protected set; }

        private bool _isSelected = false;
        public bool IsSelected
        {
            get { return (bool)_isSelected; }
            set
            {
                bool oldValue = _isSelected;
                _isSelected = value;
                if (oldValue != _isSelected)
                {
                    OnPropertyChanged("IsSelected");
                }
            }
        }

        protected bool _isAnimated = false;
        public bool IsAnimated
        {
            get { return (bool)_isAnimated; }
            set
            {
                _isAnimated = value;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = this.PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                ParentLayer = null;

                //for (int a = 0; a < KeyFrames.Count; a++)
                //{
                //    KeyFrames[a].Dispose();
                //}
                //KeyFrames.Clear();
                PropertyChanged = null;
            }
        }
    }
}
